package com.database.mapper;


import com.database.character.Praise;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PraiseMapper {

  //添加点赞
  @Insert("insert into praise(user_id, post_id) values (#{userId}, #{postId})")
  int addPraise(Praise praise);

  //取消点赞
  @Delete("delete from praise where praise_id = #{praiseId}")
  int deleteByPraiseId(Integer praiseId);

  //根据praiseId查询点赞
  @Delete("select * from praise where praise_id = #{praiseId}")
  Praise getByPraiseId(Integer praiseId);

  //根据userId查询点赞
  @Select("select * from praise where user_id = #{userId}")
  List<Praise> getPraiseByUid(Integer userId);

  //根据userId和postId查询点赞
  @Select("select * from praise where user_id = #{userId} and post_id = #{postId}")
  Praise getPraiseByUidAndPid(Integer userId, Integer postId);

  @Delete("delete from praise where user_id = #{userId} and post_id = #{postId}")
  int deleteByUidAndPid(Integer userId, Integer postId);
}
